import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    user: {},
  },
  getters: {},
  mutations: {
    updateUserInfo(state, payload) {
      state.user = payload
      // 存入vuex后还不够, 还需要存入sessionStorage
      sessionStorage.setItem('user', JSON.stringify(payload))
    },
  },
  actions: {
    login(store) {
      // 执行异步任务,发送请求,得到结果后
      store.commit('updateUserInfo', 用户对象)
    },
  },
  modules: {},
})
